package com.wealth.bbs.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wealth.bbs.entity.Reply;
import com.wealth.bbs.service.IReplyService;
import com.wealth.bbs.vo.ReplyVO;
import com.wealth.member.entity.Member;
import com.wealth.system.web.controller.BaseController;

import iaas.utils.ResultObject;

/**
 * 论坛
 * @author chan
 *
 */
@Controller
@RequestMapping(value = "/bbs/reply")
public class ReplyController extends BaseController {
	
	Logger logger = Logger.getLogger(ReplyController.class);
	
	@Autowired
	private IReplyService replyService;
	
	@ModelAttribute
	public void init(Model model){
		
	}

	/** 
	 * 回帖新增
	 */
	@RequestMapping(value="/create",method = RequestMethod.POST)
	@ResponseBody
	public ResultObject create(Reply reply,HttpServletRequest request){
		try {
			reply.setMember(new Member(memberid));
			return replyService.saveReply(reply);
		} catch (Exception e) {
			return new ResultObject("999","回帖错误", e.getMessage()); 
		}
	}
	
	
	/** 
	 * 回帖加载
	 */
	@RequestMapping(value="/more",method = RequestMethod.POST)
	@ResponseBody
	public ResultObject replyAjax(
			@RequestParam Long topicid,
			@RequestParam(defaultValue="-1") Integer index,
			@RequestParam(defaultValue="10") Integer offset) {
		try {
			List<ReplyVO> volist = replyService.ajaxReplyVO(topicid, memberid, index, offset);
			return new ResultObject("000","回帖加载更多成功", volist);
		} catch (Exception e) {
			return new ResultObject("999","回帖加载更多错误", e.getMessage());
		}
	}
	
}
